package com.gcc.crudmysqldemotext.service;

import com.gcc.crudmysqldemotext.model.Device;
import com.gcc.crudmysqldemotext.repository.DeviceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;

@Service
public class DeviceService {
    @Autowired
    private DeviceRepository deviceRepository;
    public Device save(Device device) {
        return deviceRepository.save(device);
    }
    public List<Device> findAll(){
        return deviceRepository.findAll();
    }
    public Optional<Device> findById(Long id) {
        return deviceRepository.findById(id);
    }

    public boolean deleteById(Long id) {
        if(deviceRepository.existsById(id)){
            deviceRepository.deleteById(id);
            return true;
        }
        return false;
    }
}
